﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LyyCMS.Core;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Http;
using LyyCommon;


namespace LyyCMS.Web.Areas.Dash.Controllers
{
    /// <summary>
    /// 后台控制器基类： 登录用户，数据库，后台通用函数
    /// </summary>
    [Filters.SignFilter]
    public class BaseController : Controller
    {
        protected readonly ILogger<BaseController> _logger;
        protected readonly LyyCMSEntities _context;

        /// <summary>
        /// 每页数据条数
        /// </summary>
        protected int pagesize = Service.LyyCMSConsts.PAGE_SIZE;
        /// <summary>
        /// 登录人ID
        /// </summary>
        protected int session_uid = 0;
        /// <summary>
        /// 登录人用户名
        /// </summary>
        protected string session_uname = "";
        public BaseController(ILogger<BaseController> loggger, LyyCMSEntities lyyCMSEntities)
        {
            _logger = loggger;
            _context = lyyCMSEntities;
        }
      
        /// <summary>
        /// 获取登录的人员信息
        /// </summary>
        /// <param name="context">需要传入当前控制器的上下文HtttpContext</param>
        public void GetSession(HttpContext context)
        {
            if (session_uid != 0)
            {
                return;
            }
            int? uid = context.Session.GetInt32(Service.LyyCMSConsts.USER_ID);
            session_uid = Utils.StrToInt(uid, 1);
            session_uname = context.Session.GetString(Service.LyyCMSConsts.ADMIN_NAME);
        }

    }
}